package com.ymatou.iapi.livebuyer.testcase;

import java.util.List;
import java.util.Random;

import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.livebuyer.parameter.SendDebugMessageBean;
import com.ymatou.iapi.livebuyer.service.SendDebugMessageCall;
import com.ymatou.iapi.trading.operate.parameter.PlaceOrderService;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.LiveRoomCallService;
import com.ymttest.database.model.LiveRoom;
import com.ymttest.database.model.Userinfo;
import com.ymttest.database.sqlwapper.JUserWapper;
import com.ymttest.database.sqlwapper.LiveRoomWapper;
/**
*发送调试信息
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_SendDebugMessage{
	private static SendDebugMessageBean senddebugmessageBean;
	private static SendDebugMessageCall senddebugmessageCall;
	private static LiveRoomWapper liveRoomWapper;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("发送调试信息");
	}

	@Before
	public void caseUp() {
		senddebugmessageBean=new SendDebugMessageBean();
		senddebugmessageCall=new SendDebugMessageCall();
		liveRoomWapper=new LiveRoomWapper();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(senddebugmessageCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SendDebugMessage_001() {
		Logger.start(true,"发送调试信息成功");
		try {
			
			List<Userinfo> list =new JUserWapper().select1KSeller();
			Userinfo uinfo = list.get(new Random().nextInt(list.size() - 1));
			String pid =PlaceOrderService.getNewProductId(uinfo.getLoginId(), uinfo.getUserId(), 10);
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(uinfo));
			LiveRoomCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), pid);
			
			LiveRoomCallService.SellerLiveOnline(createlive.getId(), createlive.getUserId());
			
			int count1=liveRoomWapper.selectLivedebugCountById(createlive.getId().toString());
			
			senddebugmessageBean.setAppId("autotest");
			senddebugmessageCall.setData(senddebugmessageBean);
			senddebugmessageCall.callService();			
			Logger.verifyEquals("ok", senddebugmessageCall.getReturnData(), "验证返回");
			
			int count2=liveRoomWapper.selectLivedebugCountById(createlive.getId().toString());
			Logger.verifyEquals(count2, count1+1, "验证debug记录多一条");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}